package com.le.ssm.core;

import com.le.ssm.core.entity.AjaxResult;
import com.le.ssm.core.exception.LoginException;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class ExceptionContollerAdvice {
    @ExceptionHandler(value = {LoginException.class})
    @ResponseBody
    public AjaxResult<String> handlerException(Exception e, HttpServletRequest request){
        return new AjaxResult<>(403,e.getMessage());
    }
    @ExceptionHandler(value = {Exception.class})
    public String error(Exception e, Model model){
        model.addAttribute("error",e);
        return "error";
    }




}
